package top.sky.log.impl;

import org.slf4j.Logger;

import java.util.Objects;

/**
 * Logger对象的包装类。
 *
 * @author shijin.liu
 * @since 2023-07-01
 */
public class LoggerWrapper extends AbstractLogger {

    public LoggerWrapper(Logger logger) {
        super(logger);
    }

    @Override
    public boolean isDebugEnabled() {
        return false;
    }

    @Override
    public void debug(String msg) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.debug(msg);
            return;
        }
        printLog(transactionId, msg);
    }

    @Override
    public void debug(String format, Object arg) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.debug(format, arg);
            return;
        }
        printLog(transactionId, format, arg);
    }

    @Override
    public void debug(String format, Object arg1, Object arg2) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.debug(format, arg1, arg2);
            return;
        }
        printLog(transactionId, format, arg1, arg2);
    }

    @Override
    public void debug(String format, Object... arguments) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.debug(format, arguments);
            return;
        }
        printLog(transactionId, format, arguments);
    }

    @Override
    public void debug(String msg, Throwable t) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.debug(msg, t);
            return;
        }
        printLog(transactionId, msg, t);
    }

    @Override
    public boolean isInfoEnabled() {
        return logger.isInfoEnabled();
    }

    @Override
    public void info(String msg) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.info(msg);
            return;
        }
        printLog(transactionId, msg);
    }

    @Override
    public void info(String format, Object arg) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.info(format, arg);
            return;
        }
        printLog(transactionId, format, arg);
    }

    @Override
    public void info(String format, Object arg1, Object arg2) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.info(format, arg1, arg2);
            return;
        }
        printLog(transactionId, format, arg1, arg2);
    }

    @Override
    public void info(String format, Object... arguments) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.info(format, arguments);
            return;
        }
        printLog(transactionId, format, arguments);
    }

    @Override
    public void info(String msg, Throwable t) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.info(msg, t);
            return;
        }
        printLog(transactionId, msg, t);
    }

    @Override
    public boolean isWarnEnabled() {
        return false;
    }

    @Override
    public void warn(String msg) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.warn(msg);
            return;
        }
        printLog(transactionId, msg);
    }

    @Override
    public void warn(String format, Object arg) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.warn(format, arg);
            return;
        }
        printLog(transactionId, format, arg);
    }

    @Override
    public void warn(String format, Object... arguments) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.warn(format, arguments);
            return;
        }
        printLog(transactionId, format, arguments);
    }

    @Override
    public void warn(String format, Object arg1, Object arg2) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.warn(format, arg1, arg2);
            return;
        }
        printLog(transactionId, format, arg1, arg2);
    }

    @Override
    public void warn(String msg, Throwable t) {

        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.warn(msg, t);
            return;
        }
        printLog(transactionId, msg, t);
    }

    @Override
    public boolean isErrorEnabled() {
        return logger.isErrorEnabled();
    }

    @Override
    public void error(String msg) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.error(msg);
            return;
        }
        printLog(transactionId, msg);
    }

    @Override
    public void error(String format, Object arg) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.error(format, arg);
            return;
        }
        printLog(transactionId, format, arg);
    }

    @Override
    public void error(String format, Object arg1, Object arg2) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.error(format, arg1, arg2);
            return;
        }
        printLog(transactionId, format, arg1, arg2);
    }

    @Override
    public void error(String format, Object... arguments) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.error(format, arguments);
            return;
        }
        printLog(transactionId, format, arguments);
    }

    @Override
    public void error(String msg, Throwable t) {
        String transactionId = getTransactionId();
        if (Objects.isNull(transactionId)) {
            logger.error(msg, t);
            return;
        }
        printLog(transactionId, msg, t);
    }
}
